const meet = require("../../database/meetingRoom");
const uuid = require("uuid");

module.exports = async (req, res, next)=>{
  const {number, config, rName} = req.body;

  if(req.power !== 0){
    res.send({
      code:4,
      msg:"权限不够"
    })
    return;
  }

  if(!number || !config || !rName){
    res.send({
      code:3,
      msg:"缺少必传参数：number, config, rName"
    })
    return;
  }

  try {
    await meet.insertMany({
      rId: "meet-" + uuid.v1(),
      rName,
      number: number-0,
      config: config.replace(/[\s,，]+/g, ",").split(","),
      state: false
    });
  
    res.send({
      code:1,
      msg:"会议室添加成功"
    });
  } catch (error) {
    res.send({
      code:2,
      msg:"会议室添加失败",
      error: error.toString()
    })
  }
}
